<?php
$a='123计算机';
echo strlen($a),"\n";//字节的个数 // 12
echo mb_strlen($a),"\n";//字符的个数 //6
$b=iconv('utf-8','GBK',$a);
echo strlen($b),"\n";// 9 字符串显示时的宽度，1个汉字是两个英文字符的宽度
//strcmp用于比较两个字符串的大小
echo strcmp("Hello","Hi"),"\n"; //-1
echo strcasecmp("hi","Hi"),"\n"; //0
echo strcasecmp("hi~","Hi"),"\n"; //1
//trim删除字符串首尾的空白
$s="   \t \t How are you?  \t  ";
echo "[$s]\n"; //[   	 	 How are you?  	  ]
echo "[", trim($s),"]\n"; //[How are you?]
echo "[", ltrim($s),"]\n"; //[How are you?  	  ]
echo "[", rtrim($s),"]\n"; //[   	 	 How are you?]
$s=",:.How are you?____";
echo "[", trim($s,"_,:."),"]\n"; //[How are you?]
//strpos查找子串在父字符中的位置，i忽略大小写，r相反的顺序
echo strpos('计算机程序设计','程序');   // 显示 9
echo stripos("I'm Happy.",'h');   // 显示 4
echo strripos("How old are you?",'o');   // 显示 13
var_dump(strpos('计算机程序设计','小程序'));   //bool(false) 没有找到
//bin2hex将字符串的每个字节依次转换为两个16进制字符
$a='123计算机';
echo bin2hex($a),"\n"; //313233e8aea1e7ae97e69cba
//chunk_split将字符串按指定的长度用指定的字符分隔开来
echo chunk_split(bin2hex($a),2,'_'),"\n"; //31_32_33_e8_ae_a1_e7_ae_97_e6_9c_ba_
//str_replace字符串替换
echo str_replace('o','ooo',"How are you?\n");//Hooow are yooou?
echo str_replace(['o', 'r'],'oo',"How are you?\n");//Hoow aooe yoou?
echo str_replace(['o', 'r'],['O','R'],"How are you?\n");//HOw aRe yOu?
echo str_replace(['o','r',' '],'',"How are you?\n");//Hwaeyu?
print_r(str_replace(['o', 'r'],['O','R'],["How are you?",'So good']));
/*
Array
(
    [0] => HOw aRe yOu?
    [1] => SO gOOd
) */
//str_repeat重复字符串若干次, 0次会返回空字符串""
echo str_repeat('Ok',3),"\n"; // OkOkOk
echo str_repeat('-',60),"\n";
//join 拼接数组元素为一个字符串
echo join(['Hi','Zhangsan']),"\n"; //HiZhangsan
echo join(', ', [123,456,789]),"\n"; //123, 456, 789